package com.service.business.base.controller;

import com.service.business.framework.log.RequestLog;
import com.service.dao.constants.ConfigConstants;
import com.service.business.base.controller.rep.ConfigRep;
import com.service.business.base.service.CoinService;
import com.service.business.base.service.ConfigService;
import com.service.core.rest.BaseController;
import com.service.core.rest.response.MultiResponse;
import com.service.core.rest.response.OneResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

/**
 * <dl>
 * <dt>back-end</dt>
 * <dd>Description:</dd>
 * <dd>Copyright: Copyright (C) 2015</dd>
 * <dd>Company: </dd>
 * <dd>CreateDate: 2019年09月24日</dd>
 * </dl>
 *
 * @author
 */
@Slf4j
@RestController()
@RequestMapping("config")
@Api(tags = "配置相关")
public class ConfigController extends BaseController {


    @Autowired
    private ConfigService configService;

    @Autowired
    private CoinService coinService;

    @ApiOperation("提币手续费配置")
    @RequestLog("提币手续费配置")
    @PostMapping("withdraw/fee")
    public OneResponse<Map<String, BigDecimal>> withdraw() {
        return successQueryOneResponse(coinService.listCoinFee());
    }

    @ApiOperation("验证码-转账配置")
    @RequestLog("验证码-转账配置")
    @PostMapping("transfer-account")
    public MultiResponse<ConfigRep> transferAccount() {
        return successQueryMultiResponse(configService.getConfigRepByGroup(ConfigConstants.Group.transfer.getCode()));
    }

    @ApiOperation("图片验证码-登录配置")
    @RequestLog("图片验证码-登录配置")
    @GetMapping("image-verify-code/{type}")
    public OneResponse<Boolean> imageVerifyCode(@PathVariable("type") String type) {
        return successQueryOneResponse(configService.configValueIsValid(ConfigConstants.IMAGE_VERIFY_CODE));
    }

    @ApiOperation("站点信息配置")
    @RequestLog("站点信息配置")
    @PostMapping("system-info")
    public OneResponse<Map<String, String>> systemInfo() {
        return successQueryOneResponse(configService.getConfig2MapByGroup(ConfigConstants.Group.base.getCode()));
    }

    @ApiOperation("app更新设置")
    @RequestLog("app更新设置")
    @PostMapping("app-update")
    public OneResponse<Map<String, String>> appUpdate() {
        return successQueryOneResponse(configService.getConfig2MapByGroup(ConfigConstants.Group.app_update.getCode()));
    }

}
